package org.okcjug.december.map;

import java.util.NavigableMap;
import java.util.TreeMap;

import org.junit.Test;
import org.okcjug.december.Collections1;

public class NavigableStuff 
{
	@Test
	public void test_doNavigableStuff()
	{	
		NavigableMap<String, String> nm = new TreeMap<String, String>();
		String key;
		
		for (String string : Collections1.getList()) 
		{
			key = string.split(" ")[0];
			nm.put(key, string);
		}
		
		System.out.println(nm.toString());
		
		System.out.println("-----print out Navigable Map nm ----");
		for (String string : nm.keySet())
		{
			System.out.println("-- " + nm.get(string));
		}
		
//		System.out.println("\nnm.floorEntry(We) " + nm.floorEntry("We"));
		
		
//		System.out.println("\nnm.floorEntry(X) " + nm.floorEntry("X"));
		
		
//		System.out.println("\nnm.ceilingEntry(X) " + nm.ceilingEntry("X"));

//		System.out.println("\n-----end of navigable stuff ----");
	}
	
	
	public void _test_tail_sub_maps()
	{
		NavigableMap<String, Integer> nm = new TreeMap<String, Integer>();
		nm.put("A", 1);
		nm.put("B", 2);
		nm.put("C", 3);
		nm.put("D", 4);
		nm.put("E", 5);
		nm.put("F", 6);
		nm.put("G", 7);
		nm.put("H", 8);
		nm.put("I", 9);
		
		System.err.println("wholeMap  " + nm);
//		System.err.println("tailMap   " + nm.tailMap("E"));
//		System.err.println("tailMap t " + nm.tailMap("F", true));
//		System.err.println("tailMap f " + nm.tailMap("F", false));
//		System.err.println("subMap    " + nm.subMap( "C", "G"));
//		
//		try
//		{
//			System.err.println("subMap    " + nm.subMap( "G", "C"));
//			fail("expected to throw IllegalArgumentException");
//		}
//		catch (IllegalArgumentException e)
//		{
//			// gulp
//		}
	}
}
